#!/usr/bin/env python  
# encoding: utf-8   

""" 
@version: v1.0 
@author: null 
@software: PyCharm 
@file: dbutils.py 
@time: 2017.3.24 22:48 
"""

import pymysql

def connDB():  # 连接数据库
    conn = pymysql.connect(host='127.0.0.1',port=3306, user="root", passwd="root", db="pymysql",charset='utf8')
    cur = conn.cursor()
    return (conn, cur)


def exeSql(conn, cur, sql):  # 插入\更新\删除
    sta=0
    try:
        sta = cur.execute(sql)
        conn.commit()
    except Exception as e:
        conn.rollback()
        print(e)
    return (sta)

def exeQuery(cur, sql):  # 查询
    cur.execute(sql)
    return (cur)

def connClose(conn, cur):  # 关闭连接，释放资源
    cur.close()
    conn.close()
